﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WarehouseWebAPP.code.DAL;
using WarehouseWebAPP.code.DAL.ParameterDSTableAdapters;

namespace WarehouseWebAPP.code.BLL
{
    public class ParameterBLL
    {
        private parameterTableAdapter ParameterDSAdapter = null;
        public parameterTableAdapter Adapter
        {
            get
            {
                if (ParameterDSAdapter == null) ParameterDSAdapter = new parameterTableAdapter();
                return ParameterDSAdapter;
            }
        }
        public void ParameterInsert(string parameter_name, string parameter_value)
        {
            if (parameter_name == null)
                throw new Exception("Parameter Name is missing");
            if (parameter_value == null)
                throw new Exception("Paraneter Value is missing");

            if (Adapter.ParameterInsert(parameter_name, parameter_value) < 1)
                throw new Exception("Parameter could not be added");
        }

        public void ParameterDelete(string parameter_name)
        {
            if (parameter_name == null)
                throw new Exception("Parameter Name is missing");
            if (parameter_name == "version" || parameter_name == "mail_address" || parameter_name == "smtp_server" || parameter_name=="mail_password")
                throw new Exception(parameter_name + " could not be deleted");

            if (Adapter.ParameterDelete(parameter_name) < 1)
                throw new Exception("Parameter could not be deleted");
        }

        public void ParameterUpdate(string parameter_name, string parameter_value)
        {
            if (parameter_name == null)
                throw new Exception("Parameter Name is missing");
            if (parameter_value == null)
                throw new Exception("Paraneter Value is missing");
            if (Adapter.ParameterUpdate(parameter_value,parameter_name ) < 1)
                throw new Exception("Parameter could not be Updated");
        }

        public ParameterDS.parameterDataTable ParameterGetByName(string parameter_name)
        {
            if (parameter_name == null)
                throw new Exception("Parameter Name is missing");
            return Adapter.ParameterGetByName(parameter_name);
        }


        public ParameterDS.parameterDataTable GetData()
        {
            return Adapter.GetData();
        }
    }
}